class Teacher < ActiveRecord::Base
  belongs_to :address
  has_many :courses_sessions
  
  
  def Teacher.get_all
    find(:all, :include => ['address'], :conditions => ['active = ?', true])
    rescue ActiveRecord::RecordNotFound
    nil
  end
  
  
  def Teacher.get_by_id(id)
    find(id, :include => ['address'], :conditions => ['active = ?', true])
    rescue ActiveRecord::RecordNotFound
    nil
  end


  def Teacher.deactivate(id)
    conn = connection
    i = conn.update("UPDATE teachers SET active = false WHERE id = #{id}")
    return i == 1  
  end
  
  
  def Teacher.activate(id)
    conn = connection
    i = conn.update("UPDATE teachers SET active = true WHERE id = #{id}")
    return i == 1
  end
  
end
